/**
 * 
 */
package main;

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
 * @author heantai
 * 2013-6-22 下午5:13:20
 * 
 */
public class Main {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws  Exception {
		int tableNum=0;
		String sourceFile="file\\test.xls";
		File f=new File(sourceFile);
		System.out.println(f.getAbsolutePath());
		Workbook rwb = Workbook.getWorkbook(new File(sourceFile));
		Sheet rs = rwb.getSheet(0);
		//获取第一行，第一列的值
		Cell c00 = rs.getCell(0, 0);//列，行
		System.out.println(rs.getColumns());
		System.out.println(rs.getRows());
		int step=0;
		for (int i = 0; i < rs.getRows(); i++) {
			if(CellType.EMPTY.equals(rs.getCell(0, i).getType())){
				i++;
				continue;
			}
			
			Table t=new Table();
			tableNum++;
			System.out.println("for ----"+rs.getCell(0, i).getContents());
			while(i<rs.getRows()&&!CellType.EMPTY.equals(rs.getCell(0, i).getType())){
				if(step==0){//表名
					String tableName=rs.getCell(0, i).getContents();
					t.setName(Util.dealTableName(tableName));
					step++;
				}else if(step==1){//表格头
					step++;
				}else if(step==2){
					//根据表格头取值设置列属性
					Column c=new Column();
					for (int j = 0; j < ColumnMapping.idx.length; j++) {
						Integer integer=ColumnMapping.idx[j];
						if(integer!=null){
							ColumnMapping.setProperty(c, j, rs.getCell(integer, i).getContents());
						}
					}
					t.addColumn(c);
					System.out.println("column:"+c);
				}
				i++;
				if(i<rs.getRows()&&CellType.EMPTY.equals(rs.getCell(0,i).getType())){
					step=0;
				}
			}
			System.out.println("table :"+t);
			System.out.println(t.toSql4Oracle());;
		}
		System.out.println("tableNum:"+tableNum);;
	}

}
